package com.kfm.am;

public abstract class BankAccount {

    private String accountNumber;
    private double balance;

    public String getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public BankAccount(String accountNumber, double balance) {
        this.accountNumber = accountNumber;
        this.balance = balance;
    }

    public abstract void withdraw(double money);
    public abstract void deposit(double money);
}

class SavingsAccount extends BankAccount {

    public SavingsAccount(String accountNumber, double balance) {
        super(accountNumber, balance);
    }

    @Override
    public void withdraw(double money) {
        if (super.getBalance() >= money) {
            super.setBalance(super.getBalance() - money);
            System.out.printf("取款成功%f,余额%f", money, super.getBalance());
        } else {
            System.out.println("余额不足，你心里没数嘛！");
        }
    }

    @Override
    public void deposit(double money) {
        super.setBalance(super.getBalance() + money);
        System.out.println("存款成功" + money);
    }
}

class CheckingAccount extends BankAccount {
    double overdraftLimit;

    CheckingAccount(String accountNumber, double balance, double overdraftLimit) {
        super(accountNumber, balance);
        this.overdraftLimit = overdraftLimit;
    }

    @Override
    public void withdraw(double money) {
        if (super.getBalance() + overdraftLimit >= money) {
            double balance = super.getBalance() - money;
            super.setBalance(balance < 0 ? 0 : balance);
            if (balance < 0) {
                this.overdraftLimit = this.overdraftLimit + balance;
            }
            System.out.printf("取款成功%f,余额%f,透支额度%f", money, super.getBalance(), overdraftLimit);
        } else {
            System.out.println("你没额度了！");
        }
    }

    @Override
    public void deposit(double money) {
        super.setBalance(super.getBalance() + money);
        System.out.println("存款成功" + money);
    }
}

class Test {
    public static void main(String[] args) {
        BankAccount account = new CheckingAccount("1001", 20000, 4000);
        BankAccount account1 = new SavingsAccount("1002", 2000);
        account1.deposit(20000);
        account1.withdraw(24000);
        account.withdraw(21000);
    }
}
